package com.pcs.controller;




import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.pcs.common.EasyPage;
import com.pcs.model.User;

public class UserController extends Controller {
	public void index() {
		
		EasyPage easyPage = new EasyPage();
		easyPage.setTotal(User.userDao.paginate(getParaToInt("page"), 10).getTotalRow());
		easyPage.setRows(User.userDao.paginate(getParaToInt("page"), 10).getList());
		
		renderJson(easyPage);
		
	}
	
	public void add() {
	}
	
	
	public void save() {
		User user = new User();
		user.set("username", getPara("username"));
		user.set("password", getPara("password"));
		user.set("email", getPara("email"));
		User.userDao.setAttrs(user);
		
	}
	
	public void edit() {
		setAttr("blog", User.userDao.findById(getParaToInt()));
	}
	
	
	public void update() {
		User user = new User();
		user.set("id", getPara("id"));
		user.set("username", getPara("username"));
		user.set("password", getPara("password"));
		user.set("email", getPara("email"));
		
		user.update();
		//User.userDao.update();
	}
	
	public void delete() {
		User.userDao.deleteById(getPara("id"));
		
	}
}
